package com.example.app3.recyclerView;

import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.recyclerview.widget.RecyclerView;
import com.example.app3.MainActivity;
import com.example.app3.R;
import com.example.app3.recyclerView.domain.Template;
import com.example.app3.ui.MyView;
import com.example.app3.util.Init;

import java.util.List;


public class ContentAdapter extends RecyclerView.Adapter<ContentAdapter.ViewHolder> {
    private List<Template> list;


    public ContentAdapter(List<Template> list) {
        this.list = list;
    }

    static class ViewHolder extends RecyclerView.ViewHolder {
        //        TextView textValue;
        ImageView imageView;
        TextView textValue2;

        public ViewHolder(View view) {
            super(view);
            imageView = (ImageView) view.findViewById(R.id.imageView2);
            textValue2 = (TextView) view.findViewById(R.id.textView2_uname);
        }
    }

    @Override

    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.row, parent, false);
        ViewHolder holder = new ViewHolder(view);
        return holder;
    }

    @Override

    public void onBindViewHolder(ViewHolder holder, int position) {
        Template temp = list.get(position);
        holder.imageView.setImageResource(temp.getImageId());
        holder.textValue2.setText(temp.getTextValue2());
        holder.itemView.setOnClickListener(v -> {
//            跳转后发生的事情
            Intent intent = new Intent(v.getContext(), MainActivity.class);
// 传递行号信息
            intent.putExtra("position", position);

            v.getContext().startActivity(intent);

        });

    }

    @Override
    public int getItemCount() {
        return list.size();


    }


}
